package com.smartleanx.module.hrm.service.examine.examineRecordRaterIndex;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.smartleanx.module.hrm.controller.admin.examine.examineRecordRaterIndex.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineRecordRaterIndex.ExamineRecordRaterIndexDO;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.util.object.BeanUtils;

import com.smartleanx.module.hrm.dal.mysql.examine.examineRecordRaterIndex.ExamineRecordRaterIndexMapper;

import static com.smartleanx.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.smartleanx.module.hrm.enums.ErrorCodeConstants.*;

/**
 * 维度评分 Service 实现类
 *
 * @author 
 */
@Service
@Validated
public class ExamineRecordRaterIndexServiceImpl implements ExamineRecordRaterIndexService {

    @Resource
    private ExamineRecordRaterIndexMapper examineRecordRaterIndexMapper;

    @Override
    public Integer createExamineRecordRaterIndex(ExamineRecordRaterIndexSaveReqVO createReqVO) {
        // 插入
        ExamineRecordRaterIndexDO examineRecordRaterIndex = BeanUtils.toBean(createReqVO, ExamineRecordRaterIndexDO.class);
        examineRecordRaterIndexMapper.insert(examineRecordRaterIndex);
        // 返回
        return examineRecordRaterIndex.getId();
    }

    @Override
    public void updateExamineRecordRaterIndex(ExamineRecordRaterIndexSaveReqVO updateReqVO) {
        // 校验存在
        validateExamineRecordRaterIndexExists(updateReqVO.getId());
        // 更新
        ExamineRecordRaterIndexDO updateObj = BeanUtils.toBean(updateReqVO, ExamineRecordRaterIndexDO.class);
        examineRecordRaterIndexMapper.updateById(updateObj);
    }

    @Override
    public void deleteExamineRecordRaterIndex(Integer id) {
        // 校验存在
        validateExamineRecordRaterIndexExists(id);
        // 删除
        examineRecordRaterIndexMapper.deleteById(id);
    }

    private void validateExamineRecordRaterIndexExists(Integer id) {
        if (examineRecordRaterIndexMapper.selectById(id) == null) {
//            throw exception(EXAMINE_RECORD_RATER_INDEX_NOT_EXISTS);
        }
    }

    @Override
    public ExamineRecordRaterIndexDO getExamineRecordRaterIndex(Integer id) {
        return examineRecordRaterIndexMapper.selectById(id);
    }

    @Override
    public PageResult<ExamineRecordRaterIndexDO> getExamineRecordRaterIndexPage(ExamineRecordRaterIndexPageReqVO pageReqVO) {
        return examineRecordRaterIndexMapper.selectPage(pageReqVO);
    }

}